public class TestClass {
    public static void main(String args[]) {
        show(new Cat());
        show(new Dog());

        Animal cat = new Cat();
        cat.eat();

        Cat c = (Cat)cat;
        c.work();
    }

    public static void show(Animal animal) {
        animal.eat();
        if (animal instanceof Cat) {
            Cat cat = (Cat)animal;
            cat.work();
        } else if (animal instanceof Dog) {
            ((Dog) animal).work();
        }
    }
}

abstract class Animal {
    abstract void eat();
}

class Cat extends Animal {
    public void eat() {
        System.out.println("猫吃");
    }

    public void work() {
        System.out.println("猫工作了");
    }
}

class Dog extends Animal {
    public void eat() {
        System.out.println("狗吃了");
    }
    public void work() {
        System.out.println("狗开始工作了");
    }
}